﻿Imports DevComponents.DotNetBar.SuperGrid
Imports DevComponents.DotNetBar.SuperGrid.Style

Public Class PROVIDER
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_MASPROVIDER As New PROVIDERSCLASS
    Dim selectProviderRow As Integer = -1

    Private Sub PROVIDER1_Load(sender As Object, e As EventArgs) Handles Me.Load
        SelectDatagridprovider()
        Dim objSelectDataprename As New PROVIDERCLASS


        DesignForm(Me)
        DesignGrid(sgvProvider)

        PROVIDER_MASPROVIDER.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridprovider()
        Dim objSelectDataprovider As New PROVIDERCLASS
        Dim PROVIDERDATA As DataTable
        PROVIDERDATA = connect.GetTable(objSelectDataprovider.selectProviderInfo_)
        sgvProvider.PrimaryGrid.DataSource = PROVIDERDATA
    End Sub

    'Private Sub cleardata()
    '    PROVIDERTxt.Text = ""
    '    REGISTERNOTxt.Text = ""

    '    CIDTxt.Text = ""

    '    NAMETxt.Text = ""
    '    LNAMETxt.Text = ""
    '    Dim sqldate As String
    '    Dim dt As New DataTable
    '    sqldate = " SELECT CURDATE() "
    '    dt = connect.GetTable(sqldate)
    '    BIRTH.Value = Convert.ToDateTime(dt.Rows(0)(0))
    '    PROTYPECmb.SelectedValue = -1
    '    STARTDATE.Value = Convert.ToDateTime(dt.Rows(0)(0))
    '    OUTDATE.Value = Convert.ToDateTime(dt.Rows(0)(0))
    '    MOVEFROMTxt.Text = ""
    '    MOVETOTxt.Text = ""
    '    F_DRCheckbox.Checked = False
    '    F_LOGINCheckbox.Checked = False
    '    providerStatusCheckbox.Checked = False
    'End Sub

    Private Sub PROVIDERGrid_CellClick_1(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles sgvProvider.CellClick
        'Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        'grid = e.GridPanel.ActiveRow
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("เลขที่ผู้ให้บริการ").Value() IsNot DBNull.Value Then
        '    PROVIDERTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("เลขที่ผู้ให้บริการ").Value()
        'Else
        '    PROVIDERTxt.Text = ""
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("REGISTERNO").Value() IsNot DBNull.Value Then
        '    REGISTERNOTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("REGISTERNO").Value()
        'Else
        '    REGISTERNOTxt.Text = ""
        'End If

        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("เลขที่บัตรประชาชน").Value() IsNot DBNull.Value Then
        '    CIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("เลขที่บัตรประชาชน").Value()
        'Else
        '    CIDTxt.Text = ""
        'End If

        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อ").Value() IsNot DBNull.Value Then
        '    NAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อ").Value()
        'Else
        '    NAMETxt.Text = ""
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("นามสกุล").Value() IsNot DBNull.Value Then
        '    LNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("นามสกุล").Value()
        'Else
        '    LNAMETxt.Text = ""
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันเกิด").Value() IsNot DBNull.Value Then
        '    BIRTH.Value = Convert.ToDateTime(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันเกิด").Value())
        'Else
        '    BIRTH.Value = DateAndTime.Now
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("PROTYPE").Value() IsNot DBNull.Value Then
        '    PROTYPECmb.SelectedValue = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("PROTYPE").Value()
        'Else
        '    PROTYPECmb.SelectedIndex = -1
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("STARTDATE").Value() IsNot DBNull.Value Then
        '    STARTDATE.Value = Convert.ToDateTime(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("STARTDATE").Value())
        'Else
        '    STARTDATE.Value = DateAndTime.Now
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("OUTDATE").Value() IsNot DBNull.Value Then
        '    OUTDATE.Value = Convert.ToDateTime(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("OUTDATE").Value())
        'Else
        '    OUTDATE.Value = DateAndTime.Now
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("MOVEFROM").Value() IsNot DBNull.Value Then
        '    MOVEFROMTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("MOVEFROM").Value()
        'Else
        '    MOVEFROMTxt.Text = ""
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("MOVETO").Value() IsNot DBNull.Value Then
        '    MOVETOTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("MOVETO").Value()
        'Else
        '    MOVETOTxt.Text = ""
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("F_DR").Value() = True Then
        '    F_DRCheckbox.Checked = True
        'Else
        '    F_DRCheckbox.Checked = False
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("F_LOGIN").Value() = True Then
        '    F_LOGINCheckbox.Checked = True
        'Else
        '    F_LOGINCheckbox.Checked = False
        'End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
        '    providerStatusCheckbox.Checked = True
        'Else
        '    providerStatusCheckbox.Checked = False
        'End If
        'connect = CONDB.NewConnection()
        'If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
        '    Try
        '        Dim Sql As String
        '        connect.BeginTrans()
        '        Sql = "UPDATE provider SET "
        '        If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
        '            Sql += "`status` = 1 "
        '        Else
        '            Sql += "`status` = 0 "
        '        End If
        '        Sql += "WHERE `provider` = '" & PROVIDERTxt.Text & "' ;"
        '        connect.ExecuteNonQuery(Sql)
        '        connect.CommitTrans()
        '    Catch ex As Exception
        '        connect.RollbackTrans()
        '        MsgBox(ex.ToString)
        '    End Try
        'End If
        'connect.Dispose()

        'connectlocal = conlocal.NewConnection()
        'If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
        '    Try
        '        Dim Sql As String
        '        connectlocal.BeginTrans()
        '        Sql = "UPDATE MASRELIGION SET "
        '        If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
        '            Sql += "[STATUS] = 1 "
        '        Else
        '            Sql += "[STATUS] = 0 "
        '        End If
        '        Sql += "WHERE [RELIGION] = '" & RELIGIONIDTxt.Text & "' ;"

        '        connectlocal.ExecuteNonQuery(Sql)
        '        connectlocal.CommitTrans()
        '    Catch ex As Exception
        '        connectlocal.RollbackTrans()
        '        MsgBox(ex.ToString)
        '    End Try
        'End If
        'connectlocal.Dispose()
        addProvider.Enabled = False
    End Sub

    Private Sub sgvProvider_CellClick(sender As Object, e As GridCellClickEventArgs) Handles sgvProvider.CellClick
        If e.MouseEventArgs.Button = Windows.Forms.MouseButtons.Right Then
            selectProviderRow = e.GridCell.RowIndex
        End If
    End Sub

    Private Sub btnEditProvider_Click(sender As Object, e As EventArgs) Handles btnEditProvider.Click
        Dim empid As String = CType(sgvProvider.PrimaryGrid.Rows(selectProviderRow), GridRow).Cells("รหัสพนักงาน").Value

        Dim newFOrm As New EDITPROVIDER(empid, PROVIDER_MASPROVIDER.txtusername_tag_)
        Dim resultForm As DialogResult = newFOrm.ShowDialog()

        If resultForm = Windows.Forms.DialogResult.OK Then
            SelectDatagridprovider()
        End If
    End Sub

    Private Sub ButtonX1_Click(sender As Object, e As EventArgs) Handles btnOpenAddprovider.Click
        Dim newFOrm As New ADDPROVIDER(PROVIDER_MASPROVIDER.txtusername_tag_)
        Dim resultForm As DialogResult = newFOrm.ShowDialog()

        If resultForm = Windows.Forms.DialogResult.OK Then
            SelectDatagridprovider()
        End If
    End Sub



    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("provider")
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        Dim nextform As New IMPORTEXCEL("provider")
        nextform.ShowDialog()
    End Sub
End Class